﻿using Iworld.Client.Framework.AuthorService;
using Iworld.ViewModel;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Client.Framework
{
    /// <summary>
    /// 充值卡充值视图模型
    /// </summary>
    public class RechargeCardViewModel : SubPageFrameViewModelBase
    {
        string password;
        string account;

        public RechargeCardViewModel()
            : base(PageCategory.充值服务.ToString(),Page.充值卡充值.ToString())
        {
            SubmitCommand = new UniversalCommand((paramater) =>
            {
                AuthorServiceClient asc = new AuthorServiceClient();
                asc.RechargeCompleted += this.WrapEventHandler<RechargeCompletedEventArgs>(RechargeCompleted);
                asc.RechargeAsync(new RechargeImport() { 
                    Account = this.Account,Password=this.Password,Token=DataManager.GetValue<string>(DataKey.Iworld_Token)
                }); 
            });
        }

        void RechargeCompleted(object sender, RechargeCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                this.ShowMsg("充值成功");
            }
            else
            {
                this.ShowError(e.Result.Error);
            }
        }
        /// <summary>
        /// 提交修改的命令
        /// </summary>
        public UniversalCommand SubmitCommand { get; set; }

        /// <summary>
        ///充值卡账号
        /// </summary>
        public string Account
        {
            get
            {
                return account;
            }
            set
            {
                if (account != value)
                {
                    account = value;
                    this.OnPropertyChanged("Account");
                }
            }
        }

        /// <summary>
        /// 充值卡密码
        /// </summary>
        public string Password
        {
            get
            {
                return password;
            }
            set
            {
                if (password != value)
                {
                    password = value;
                    this.OnPropertyChanged("Password");
                }
            }
        }
    }
}
